<?php 
defined('IN_TS') or die('Access Denied.');

	$provincce = trim($_POST['province']);
	$city = trim($_POST['city']);
	$begintime = trim($_POST['begintime']);
	$endtime = trim($_POST['endtime']);

	$str='idcard<>null';

	if($begintime!=''){
		$begintime = strtotime($begintime);
		if($endtime==''){
			$endtime = time();
		}else{
			$endtime = strtotime($endtime);
		}

		$str =$str.' and addtime>'.$begintime.' and addtime<'.$endtime;
	}
	if($provincce!=''){
		$str = $str.' and province='.$provincce;
	}
	if($city!=''){
		$str = $str.' and city='.$city;
	}

	//$str = $str." group by userid";
	//Excel表格式,这里简略写了8列
	$letter = array('A','B','C','D','E');
	//表头数组
	$tableheader = array('姓名','身份证号','服务处所','服务次数','所在地');
	//$arrDuty = $this->findAll('duty',$str,null,null,null,null);
	$sql="select username,idcard,groupids,count_duty,province,city from ts_user_info where ".$str;
	$arrUser=$this->db->fetch_all_assoc ( $sql );
	$data=array();
	foreach ( $arrDuty as $key => $item ){
		$strGroup = explode(',',$item['groupids']);
		$group= aac('group')->find('group',array('groupid'=>$strGroup[0]));
		$data[$key]=array($item['username'],$item['idcard'],$group['groupname'],$item['count_duty'],$item['province'].$item['city']);
	}
	$filename='志愿者名单.xls';
	create_xls($data,$letter,$tableheader,$filename);

	output_xls($data,$filename);
	getJson('操作成功',1,1);
